﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static Random r = new Random();
        static Referee referee = new Referee();
        static NPC npc = new NPC();
        static Player player = new Player();

        static int PlayerSum = 0;
        static int NPCSum = 0;
        static int Sum = 1;

        static NPC npc1 = new NPC("刘备");
        static NPC npc2 = new NPC("孙权");
        static NPC npc3 = new NPC("曹操");
        static void Main(string[] args)
        {
            ASD();
        }
        static void ASD() 
        {
            Console.WriteLine("************************************");
            Console.WriteLine("*************猜拳，开始*************");
            Console.WriteLine("************************************");
            Console.WriteLine("出拳规则：1、石头 2、剪刀 3、布");
            Console.WriteLine("请选择对手：1、刘备 2、孙权 3、曹操");
            int a = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入您的姓名：");
            string name = Console.ReadLine();
            star(a, name);
        }
        static void star(int a , string name)
        {
            while (true)
            {
                Player player1 = new Player(name);

                switch (a)
                {
                    case 1:
                        Console.WriteLine("{0} VS {1}", name, npc1.Name);
                        VS(player1.Name, npc1.Name, player1);
                        break;
                    case 2:
                        Console.WriteLine("{0} VS {1}", name, npc2.Name);
                        VS(player1.Name, npc1.Name, player1);
                        break;
                    case 3:
                        Console.WriteLine("{0} VS {1}", name, npc3.Name);
                        VS(player1.Name, npc1.Name, player1);
                        break;
                }
            }
            
        }
        static void VS(string name, string NPC, Player player1)
        {
            int a = player.Move();
            int b = r.Next(1, 4);
            while (true)
            {

            }
            switch (a)
            {
                case 1:
                    Console.WriteLine("{0}出石头", player1.Name);
                    npc.Move(NPC, b);
                    
                    break;
                case 2:
                    Console.WriteLine("{0}出剪刀", player1.Name);
                    npc.Move(NPC, b);
                    
                    break;
                case 3:
                    Console.WriteLine("{0}出布", player1.Name);
                    npc.Move(NPC, b);
                    
                    break;
            }
            if (a == b)
            {
                Console.WriteLine("平局！");
            }
            else if (a == 1 && b == 2 || a == 2 && b == 3 || a == 3 && b == 1)
            {
                Console.WriteLine("{0}获胜！", player1.Name);
                PlayerSum = PlayerSum + 1;
            }
            else if (a == 1 && b == 3 || a == 2 && b == 1 || a == 3 && b == 2)
            {
                Console.WriteLine("{0]获胜！", npc.Name);
                NPCSum = NPCSum + 1;
            }
            Console.WriteLine("是否开始下一轮游戏？(y/n)");
            string m = Console.ReadLine();
            if (m == "y")
            {
                star(a,name);
                Sum = Sum + 1;
            }
            else if( m == "n")
            {
                Console.WriteLine("=======================");
                Console.WriteLine("{0} VS {1}", name, npc1.Name);
                Console.WriteLine("对战次数{0}",Sum);
                Console.WriteLine("姓名：{0} 得分： {1}",name,PlayerSum);
                Console.WriteLine("姓名：{0} 得分： {1}", npc1.Name, NPCSum);

                if (NPCSum > PlayerSum)
                {
                    Console.WriteLine("结果：{0}获胜！", npc1.Name);
                }
                else if (NPCSum == PlayerSum)
                {
                    Console.WriteLine("结果：平局！");
                }
                else
                {
                    Console.WriteLine("结果：{0}获胜！", name);
                }
                Exit();
            }
            else
            {
                Console.WriteLine("输入错误！");
            }
        }

        static void Exit() 
        {
            Console.WriteLine("是否开始下一局游戏？(y/n)");
            string n = Console.ReadLine();
            if (n == "y")
            {
                ASD();
                PlayerSum = 0;
                NPCSum = 0;
                Sum = 1;
            }
            else if (n == "n")
            {
                Console.WriteLine("游戏结束，按下任意键退出！");
                System.Environment.Exit(0);
            }
        }
    }
}
